home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_08 / dwyer2 / line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  878 b   |  48 lines

  1. /* Listing 4        Floating Point and Fixed Point Line Routines */
  2.  
  3. /*
  4.     These functions rely on the Borland graphics library
  5. */
  6.  
  7. #include <graphics.h>
  8.  
  9.  
  10. #define FixedPointShiftAmount 8
  11.  
  12. #define FPToInteger( FP )  ( FP >> FixedPointShiftAmount )
  13. #define IntegerToFP( Integer )  ( Integer << FixedPointShiftAmount )
  14.  
  15.  
  16. typedef long FixedPnt;
  17.  
  18.  
  19. void FloatingPointLine( float x1, float y1, float x2, float y2 )
  20. {
  21.     float t, x, y;
  22.  
  23.     for( t = 0.0; t < 1.0; t += 0.05 )
  24.     {
  25.         x = x1 + ( x2 - x1 ) * t;
  26.         y = y1 + ( y2 - y1 ) * t;
  27.  
  28.         putpixel( x, y, 12 );
  29.     }
  30. }
  31.  
  32.  
  33. void FixedPointLine( short x1, short y1, short x2, short y2 )
  34. {
  35.     // This dt gives 128 steps
  36.     FixedPnt t, dt = 1 << ( FixedPointShiftAmount - 6 );
  37.     short x, y;
  38.  
  39.     for( t = 0; t < IntegerToFP( 1 ); t += dt )
  40.     {
  41.         x = x1 + FPToInteger( (( x2 - x1 ) * t ));
  42.         y = y1 + FPToInteger( (( y2 - y1 ) * t ));
  43.  
  44.         putpixel( x, y, 13 );        
  45.     }
  46. }
  47.  
  48.